<%--
  Created by IntelliJ IDEA.
  User: bonnie
  Date: 2021/8/10
  Time: 3:53 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>用户信息管理系统</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="${pageContext.request.contextPath}/js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
    <script>
        $(function() {
            $("#selectAll").click(function() {
                $("input[name='ids']").prop("checked",this.checked);
            });
        })
        function deleteSelected() {
            var isSubmit = false;
            // 只有选中一些数据时, 才会提交
            // $("input[name='ids']")
            $.each($("input[name='ids']"), function(i,obj) {
                if(obj.checked) {
                    isSubmit = true;
                }
            });
            // 手动提交表单 submit()
            if (isSubmit) {
                $("#tableForm").get(0).submit();
            }
        }
    </script>
</head>
<body>
<div class="container">
    <h3 style="text-align: center">用户信息列表</h3>
    <form class="form-inline" style="float: left">
        <div class="form-group">
            <label for="name">姓名</label>
            <input type="text" class="form-control" value="${con.name[0]}" name="name" id="name" placeholder="请输入姓名">
        </div>
        <div class="form-group">
            <label for="address">籍贯</label>
            <input type="text" class="form-control" value="${con.address[0]}" name="address" id="address" >
        </div>
        <div class="form-group">
            <label for="email">邮箱</label>
            <input type="text" name="email" value="${con.email[0]}" class="form-control" id="email" >
        </div>
        <button type="submit" class="btn btn-default">查询</button>
    </form>

    <a class="btn btn-primary" style="float: right;margin: 5px" href="javascript:void(0)" onclick="deleteSelected()">删除选中</a>
    <a class="btn btn-primary" style="float: right;margin: 5px" href="add.jsp">添加联系人</a>

    <form id="tableForm" action="${pageContext.request.contextPath}/userInfo/DeleteSelectedUserInfoServlet">
        <table border="1" class="table table-bordered table-hover">
            <tr class="success">
                <th><input id="selectAll" type="checkbox"></th>
                <th>编号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>籍贯</th>
                <th>QQ</th>
                <th>邮箱</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${pb.list}" var="userInfo" varStatus="s">
                <tr>
                    <th><input type="checkbox" name="ids" value="${userInfo.id}"></th>
                    <td>${s.count}</td>
                    <td>${userInfo.name}</td>
                    <td>${userInfo.gender}</td>
                    <td>${userInfo.age}</td>
                    <td>${userInfo.address}</td>
                    <td>${userInfo.qq}</td>
                    <td>${userInfo.email}</td>
                    <td><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/EditUserInfoServlet?id=${userInfo.id}">修改</a>
                        &nbsp;<a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/DeleteByIdServlet?id=${userInfo.id}">删除</a></td>
                </tr>
            </c:forEach>

        </table>
    </form>

    <nav aria-label="Page navigation">
        <ul class="pagination">
            <%-- 判断上一页 --%>
            <c:if test="${pb.currentPage == 1}">
                <li class="disabled">
                    <a href="javascript:void(0)" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pb.currentPage != 1}">
               <li>
                <a href="${pageContext.request.contextPath}/userInfo/QueryWithPageServlet?currentPage=${pb.currentPage-1}&pageSize=${pb.pageSize}&name=${con.name[0]}&address=${con.address[0]}&email=${con.email[0]}" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
               </li>
            </c:if>

            <%-- 显示页码 --%>
            <c:forEach begin="1" end="${pb.totalPage}" var="i">
                <li ${i==pb.currentPage?'class="active"' : ''}>
                    <a href="${pageContext.request.contextPath}/userInfo/QueryWithPageServlet?currentPage=${i}&pageSize=${pb.pageSize}&name=${con.name[0]}&address=${con.address[0]}&email=${con.email[0]}">${i}</a></li>
            </c:forEach>

            <%-- 判断下一页 --%>
            <c:if test="${pb.currentPage == pb.totalPage}">
                <li class="disabled">
                    <a href="javascript:void(0)" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pb.currentPage != pb.totalPage}">
                <li>
                    <a href="${pageContext.request.contextPath}/userInfo/QueryWithPageServlet?currentPage=${pb.currentPage+1}&pageSize=${pb.pageSize}&name=${con.name[0]}&address=${con.address[0]}&email=${con.email[0]}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>

            <span style="font-size: 22px;margin-left: 10px">共${pb.totalCount}条数据, 共${pb.totalPage}页</span>
        </ul>
    </nav>

    </div>
</body>
</html>

